package com.bqy.myokgo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.apkfuns.logutils.LogUtils;
import com.bqy.myokgo.base.MyBaseActivity;
import com.bqy.myokgo.base.manager.AppManager;
import com.bqy.myokgo.base.manager.event.HttpEventNO;
import com.bqy.myokgo.base.manager.event.HttpEventOK;
import com.bqy.myokgo.base.okgo.OKHttp;
import com.bqy.myokgo.base.okgo.bean.GuestBean;
import com.bqy.myokgo.base.okgo.bean.XXResponse;
import com.bqy.myokgo.base.okgo.callback.DialogCallback;
import com.bqy.myokgo.base.okgo.callback.HttpManagerCallback;
import com.bqy.myokgo.fragment.lyout.FragmentLyoutActivity;
import com.bqy.myokgo.fragment.pager.FragmentActivity;
import com.bqy.myokgo.utils.NoDoubleClickListener;
import com.bqy.myokgo.utils.OnAppListener;
import com.bqy.myokgo.utils.ToastUtils;
import com.lzy.okgo.model.Response;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends MyBaseActivity implements OnAppListener.OnHttpListener {


    @Override
    public View setContentView() {
        return View.inflate(this, R.layout.activity_main, null);
    }

    @Override
    public void iniGreate(Bundle savedInstanceState) {
        super.iniGreate(savedInstanceState);
        mToolBar.isToolBar(false);

        final Map map = new HashMap();
        map.put("Token", "79a4ddc3ff957cb1f90dc5528f7be26d1.0.76Y87HH1M3JJQCWEA7QCP2FGW41D48922E12F339D56386C1D58D767E5C6A1217A");
        map.put("UserId", "31808291029285806");
        map.put("DepartDate", "2018-12-01");
        map.put("DepartCityCode", "CTU");
        map.put("ArriveCityCode", "PEK");
        map.put("FlightNo", "CA4111");
        map.put("CabinCode", "F");
        map.put("AirLineCode", "CA");
        map.put("CabinPrice", "1780");
        map.put("Discount", "30.5");


        Button button = findViewById(R.id.aaaaa);
        Button cccccc = findViewById(R.id.cccccc);
        Button dddddd = findViewById(R.id.dddddd);
        Button eeeeee = findViewById(R.id.eeeeee);
        Button ffffff = findViewById(R.id.ffffff);
        Button gggggg = findViewById(R.id.gggggg);
        Button hhhhhh = findViewById(R.id.hhhhhh);
        Button iiiiii = findViewById(R.id.iiiiii);

        cccccc.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, HttpActivity.class));
            }
        });
        dddddd.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, LinqActivity.class));
            }
        });
        button.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                for (int i = 0; i < 20; i++) {
                    OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                            , new DialogCallback<XXResponse<GuestBean>>(MainActivity.this) {
                                @Override
                                public void onSuccess(Response response) {

                                }

                                @Override
                                public void onError(Response<XXResponse<GuestBean>> response) {
                                    super.onError(response);
                                }
                            });
                }
            }
        });
        eeeeee.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, ReActivity.class));
            }
        });
        ffffff.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, FragmentActivity.class));
            }
        });
        gggggg.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, FragmentLyoutActivity.class));
            }
        });
        hhhhhh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "1") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "2") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "3") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "4") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "5") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });
                OKHttp.post(map, "http://118.190.0.224:10006/api/FlightInfo/SearchGuestRule"
                        , new HttpManagerCallback<XXResponse<GuestBean>>(MainActivity.this, "6") {
                            @Override
                            public void onSuccess(Response response) {
                            }
                        });

            }
        });
        iiiiii.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                startActivity(new Intent(MainActivity.this, SetUpActivity.class));
            }
        });
    }

    //池子全部成功
    @Override
    public void onHttpOK(HttpEventOK event) {
        LogUtils.e(event.httpEventList);
    }

    //有失败
    @Override
    public void onHttpNO(HttpEventNO event) {
        LogUtils.e(event.response);
    }

    private long lastBackPressed;

    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - lastBackPressed > 2000) {
            ToastUtils.show("飒飒的飒飒大苏打盛大的");
            lastBackPressed = System.currentTimeMillis();
        } else {
            AppManager.getInstance().AppExit(this);
        }
    }


}
